﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using BLL;
using MOD;

namespace MapServer.Adhs
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             String sReturnValue = String.Empty;
            if (Request["userId"] != null)
            {
                sReturnValue = GetDevotedCount(Convert.ToInt64(Request["userId"]), Convert.ToInt64(Request["customerId"]));
            }
            Response.Write(sReturnValue);
        }
         
        public String GetDevotedCount(Int64 iUserId,Int64 iCustomerId)
        {
            B_AdInfo bAo = new B_AdInfo();
            B_AdRepost bAt = new B_AdRepost();
            int iOriginality = 0;   //创意
            int iCharm = 0;         //魅力
            int iContributions = 0; //贡献
            int iChildShoes = 0;    //童鞋
            String sValue = "998";
            try
            {
                DataTable dOriginality = new DataTable();
                DataTable dContributions = new DataTable();
                DataTable dCharm = new DataTable();
                DataTable dRepost1 = new DataTable();
                DataTable dRepost2 = new DataTable();

                dOriginality = bAo.SelectUserIdCount(iCustomerId);
                dContributions = bAo.SelectOtherUserId(iCustomerId);
                dCharm = bAt.SelectRepost(iCustomerId);
                dRepost1 = bAt.SelectUserRepostCount(iCustomerId);
                dRepost2 = bAt.SelectRepostUserCount(iCustomerId);

                if (dOriginality.Rows.Count != 0)
                {
                    iOriginality = Convert.ToInt32( dOriginality.Rows.Count);
                }
                if(dContributions.Rows.Count != 0)
                {
                    iCharm = Convert.ToInt32(dContributions.Rows[0]["count"].ToString().Trim());
                }
                if(dCharm.Rows.Count != 0)
                {
                    iContributions = Convert.ToInt32(dCharm.Rows[0]["count"].ToString().Trim());
                }
                iChildShoes = dRepost1.Rows.Count + dRepost2.Rows.Count;

                sValue = "001";
                String[] sArrayList = new String[1];
                sArrayList[0] = "\"" + iUserId.ToString() + "\"" + "," + "\"" + iOriginality.ToString() + "\"" + "," + "\"" + iCharm + "\"" + "," + "\"" + iContributions.ToString() + "\"" + "," + "\"" + iChildShoes.ToString()+ "\"";
                sValue = JsonParameters.CreateJsonParameters(String.Empty, sValue,sArrayList);
            }
            catch
            {
                sValue = JsonParameters.CreateJsonParameters(String.Empty, sValue);            
            }
           
            return sValue; 
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
